package cn.lijiguo.concurrency.part1.threadobjectmethods;

/**
 * JoinThreadState
 * 先调用 join() 再 mainThread.getState() 获取线程的状态
 * @author lijiguo
 * @date 2020/1/7 14:23
 */
public class JoinThreadState {

    public static void main(String[] args) {
        Thread mainThread = Thread.currentThread();

        Thread childThread = new Thread(() -> {
            try {
                Thread.sleep(5000);
                System.out.println("主线程的状态: " + mainThread.getState());
                System.out.println(Thread.currentThread().getName() + " 运行结束！");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "childThread");

        childThread.start();
        System.out.println("等待子线程执行完成=======");
        try {
            childThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("子线程执行完成~~~~~~");
    }
}
